package nuist.hanniko.stu.webbackend.service.impls;

import nuist.hanniko.stu.webbackend.dao.redis.LoginStateDAO;
import nuist.hanniko.stu.webbackend.service.LoginStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class LoginStateServiceImpl implements LoginStateService {

    private final LoginStateDAO loginStateDAO;

    private static final int EXPIRED_TIME = 24 * 60 * 60;

    @Autowired
    public LoginStateServiceImpl(LoginStateDAO loginStateDAO) {
        this.loginStateDAO = loginStateDAO;
    }

    @Override
    public boolean isActive(String token) {
        return loginStateDAO.getToken(token) == null;
    }

    @Override
    public void updateState(String token) {
        loginStateDAO.setExpiredToken(token, EXPIRED_TIME);
    }
}
